<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M/vue/2.6.14/vue.js" type="application/javascript"></script>
</head>
<body>
  <div id="app">
    <ul><li v-for="item in list">{{item}}</li></ul>
    <div>username={{obj.username}}</div>
    <div>age={{obj.age}}</div>
  </div>
</body>
<script>
  new Vue({
    data() {
      return {
        list: [1,2,3],
        obj: {
          username: 'zs'
        }
      }
    },
    created() {
      // this.list[3] = 4
    },
    mounted() {
      //挂载数据到页面之后,数据操作注意事项
      //数组不能直接通过索引值新增元素,不是响应式
      // this.list[3] = 4
      //解决办法
      // this.$set(this.list, 3, 4)
      // this.list.push(4)
      //对象不能直接给不存在的属性赋值,不是响应式
      // this.obj.age = 20
      // 解决办法
      // this.$set(this.obj, 'age', 20)
      this.obj = {
        ...this.obj,
        age: 20
      }

    },
    el: '#app'
  })
</script>
</html>
